<?php 
/**
 * 统计控制器
 * @Author    紫梦
 * @DateTime  2018-01-26
 * @copyright 响响租车
 * @version   1.0
 */
namespace app\index\controller;
use app\common\model\Cars;
use app\common\model\Brand;

class Charts extends Base
{
	public function cars()
	{

		$brand = Brand::column('id');
		// dump($brand);
		$model = Brand::withCount(['cars'])->select($brand);
		foreach ($model as $key => $value) {
			$array[$key]['value'] = $value->cars_count;
			
			$array[$key]['name'] = $value->name;
		}
		rsort($array);
		$name = array_column($array,'name');
		$count = Cars::count();
		$this->assign('brand',json_encode($array));	
		$this->assign('name',json_encode($name));	
		$this->assign('count',$count);	
		return $this->fetch();
	}
}